<template>
  <div>
      <div>
      <el-form  :inline="true" :model="A">
            <el-form-item prop="" label="医生姓名">
                <el-input v-model="A.userName" placeholder="医生姓名"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="success" icon="el-icon-search" @click="mhcAdmin()"></el-button>
            </el-form-item>
            
            <el-button type="primary" style="margin-left: 300px" @click="tianjia()">添加医生信息</el-button>
        </el-form>
    </div>
      <div>
          <el-button type="primary" @click="tianjia()">添加</el-button>
        <el-table border :data="Data.slice((currentPage-1)*pagesize,currentPage*pagesize)">
        <el-table-column label="用户名" prop="userName"></el-table-column>
                <el-table-column prop="portrait" label="头像" align="center">
          <template slot-scope="scope">            
            <img :src="scope.row.portrait"  min-width="70" height="70" />
          </template>  
        </el-table-column>
        <el-table-column label="性别" prop="sex" ></el-table-column>
        <el-table-column label="手机号码" prop="userPhone"></el-table-column>
        <el-table-column label="邮箱" prop="email"></el-table-column>
        <el-table-column label="角色" prop="userRole"></el-table-column>
        <el-table-column label="添加时间" prop="creationTime"></el-table-column>
        <el-table-column label="操作" v-slot="a">
            <el-button type="primary" @click="xiugai(a.row)">修改</el-button>
            <el-button type="primary" @click="shanchu(a.row.id)">删除</el-button>
        </el-table-column>
      </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[3, 5, 7]"
                :page-size="pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="Data.length">
        </el-pagination>
      </div>
      <div>
          <el-dialog title="新增管理员" :visible.sync="addmtk">
              <el-form :model="add">
                <el-form-item label="用户名：">
                    <el-input v-model="add.userName" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="用户头像：">
                    <el-input v-model="add.portrait" placeholder="请输入内容"></el-input>
                </el-form-item>
                 <el-form-item label="性别：">
             <el-select v-model="add.sex" clearable  placeholder="请选择" >
                <el-option label="男" value="男"></el-option>
                <el-option label="女" value="女"></el-option>
                <el-option label="张国栋" value="傻"></el-option>
              </el-select>
          </el-form-item>
                <el-form-item label="手机号码：">
                    <el-input v-model="add.userPhone" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="邮箱：">
                    <el-input v-model="add.email" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="角色：">
                    <el-input v-model="add.userRole" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-button type="primary" @click="AddAdmin()">确定</el-button>
                <el-button type="primary" @click="addmtk=false">取消</el-button>
              </el-form>
          </el-dialog>
      </div>
      <div>
          <el-dialog title="修改管理员" :visible.sync="updmtk">
              <el-form :model="upd">
                <el-form-item label="用户名：">
                    <el-input v-model="upd.userName" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="用户头像：">
                    <el-input v-model="upd.portrait" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="性别：">
                    <el-input v-model="upd.sex" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="手机号码：">
                    <el-input v-model="upd.userPhone" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="邮箱：">
                    <el-input v-model="upd.email" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-form-item label="角色：">
                    <el-input v-model="upd.userRole" placeholder="请输入内容"></el-input>
                </el-form-item>
                <el-button type="primary" @click="UpdAdmin()">确定</el-button>
                <el-button type="primary" @click="updmtk=false">取消</el-button>
              </el-form>
          </el-dialog>
      </div>
  </div>
</template>

<script>
export default {
   created(){
       this.findAdminAll();
   },
    data(){
        return{
            A:{},
            Data:[],
            addmtk:false,
            add:{},
            upd:{},
            updmtk:false,
            headertitle: "",
            centerDialogVisible:false,
            pagesize:3,
            currentPage:1,
        }
    },
    methods:{
        findAdminAll(){
            this.$axios.get("/user/user/doctor/ren/findAdminAll").then(res=>{
                this.Data = res.data.data.list
            })
        }, 
        tianjia(){
            this.addmtk=true;
        },
        AddAdmin(){
            this.$axios.post("/user/user/doctor/ren/AddAdmin",this.add).then(res=>{
                console.log(this.add)
                this.add={}
                this.addmtk=false
                this.findAdminAll();
            })
        },
        xiugai(row){
            this.updmtk=true;
            this.upd={...row}
        },
        UpdAdmin(){
            this.$axios.post("/user/user/doctor/ren/UpdAdmin",this.upd).then(res=>{
                this.upd={}
                this.updmtk=false
                this.findAdminAll();
            })
        },
        mhcAdmin(){
            this.$axios.get("/user/user/doctor/ren/mhcAdmin",
            {  	params:{
                userName:this.A.userName}}).then(res=>{
                this.Data = res.data.data.list;
                })
        },
        shanchu(id){
            this.$axios.get("/user/user/doctor/ren/shanchu",{params:{id:id}}).then(res => {
               if(res.data){
                  this.$message({
                      message:'删除成功',
                  })
                  this.findAdminAll() 
               }else{
                   this.$message.error("删除失败")
               }
            })
        },
        handleSizeChange(size) {
            this.pagesize = size;
      },
       handleCurrentChange(currentPage) {
            this.currentPage = currentPage;
      }
  
    }
}
</script>

<style>

</style>